package com.dwms.controller;

import com.dwms.entity.PageResponse;
import com.dwms.entity.QueryRequest;
import com.dwms.entity.Result;
import com.dwms.entity.system.menu.request.MenuQueryRequest;
import com.dwms.entity.system.menu.request.MenuRequest;
import com.dwms.entity.system.menu.response.MenuResponse;
import com.dwms.feign.system.MenuFeignClient;
import com.dwms.utils.WebUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @ClassName: MenuMapper
 * @Description: Menu
 * @Create 2022/03/05 20:47
 * @Author WH
 * @Since 2.0.0
**/
@Tag(name = "菜单管理")
@RestController(value = "MenuController")
@RequestMapping(value = "/system/menu")
@RequiredArgsConstructor
public class MenuController {

    private final HttpServletRequest request;
    private final MenuFeignClient menuFeignClient;

    /**
     * 新增菜单
     * @param menuRequest
     * @return
     */
    @Operation(summary= "新增菜单")
    @PostMapping("/save")
    public Result save(@RequestBody MenuRequest menuRequest) {
        WebUtil.getAdminRequest(request,menuRequest);
        return menuFeignClient.save(menuRequest);
    }

    /**
     * 更新菜单
     * @param menuRequest
     * @return
     */
    @Operation(summary= "更新菜单")
    @PostMapping("/update")
    public Result update(@RequestBody MenuRequest menuRequest) {
        WebUtil.getAdminRequest(request,menuRequest);
        return menuFeignClient.update(menuRequest);
    }

    /**
     * 分页查询菜单
     * @param query
     * @return
     */
    @Operation(summary= "分页查询菜单")
    @PostMapping("/findPage")
    public Result<PageResponse<MenuResponse>> findPage(@RequestBody MenuQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return menuFeignClient.findPage(query);
    }

    /**
     * 根据ID查询菜单
     * @param query
     * @return
     */
    @Operation(summary= "根据ID查询菜单")
    @PostMapping("/findById")
    public Result<MenuResponse> findById(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return menuFeignClient.findById(query);
    }

    /**
     * 删除菜单
     * @param query
     * @return
     */
    @Operation(summary= "删除菜单")
    @PostMapping("/delete")
    public Result delete(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return menuFeignClient.delete(query);
    }

}
